package northburns.gamedude.core.model.standard;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Everything needs to have a copy constructor!!!
 * 
 * @author Aki
 * 
 */
public class GameState {

	public static class Zone implements Cloneable {
		public final int id;
		public int parentZoneId;
		public String name;

		protected Zone(int id) {
			this.id = id;
		}

		protected Zone(Zone z) {
			this(z.id);
			parentZoneId = z.parentZoneId;
			name = z.name;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + id;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Zone other = (Zone) obj;
			if (id != other.id)
				return false;
			return true;
		}
	}

	public static class Piece {
		public final int id;
		public int zoneId;

		protected Piece(int id) {
			this.id = id;
		}

		protected Piece(Piece p) {
			this(p.id);
			zoneId = p.zoneId;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + id;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Zone other = (Zone) obj;
			if (id != other.id)
				return false;
			return true;
		}
	}
	
	public static class Visibility {
		public enum VISIBILITY_MODE {
			DEFAULT_VISIBLE,DEFAULT_HIDDEN
		}
		VISIBILITY_MODE visibilityMode;
		Set<String> hiddenFromThesePlayers;
		Set<String> visibleToThesePlayers;
		public Visibility() {
			hiddenFromThesePlayers = new HashSet<String>();
			visibleToThesePlayers = new HashSet<String>();
			visibilityMode = VISIBILITY_MODE.DEFAULT_VISIBLE;
		}
	}
	
	public static class Value  {
		
		public Value() {
			
		}
		public Value(Value v) {
			this();
		}
	}

	public Set<Zone> zones;
	public Set<Piece> pieces;

	public GameState() {
		zones = new HashSet<Zone>();
		pieces = new HashSet<Piece>();
	}

	public GameState(GameState gs) {
		this();
		for (Zone z : gs.zones) {
			zones.add(new Zone(z));
		}
		for (Piece p : gs.pieces) {
			pieces.add(new Piece(p));
		}
	}
}
